<%@page import="shop.factory.DAOFactory"%>
<%@page import="shop.vo.ProTypeBean"%>
<%@page import="shop.util.IPTimeStamp"%>
<%@page import="com.jspsmart.upload.SmartUpload"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<%
	String type = request.getParameter("type");
	SmartUpload mySmartUpload = new SmartUpload();
	mySmartUpload.initialize(pageContext);
	mySmartUpload.upload();
	IPTimeStamp its = new IPTimeStamp(request.getRemoteAddr());
	String ext = mySmartUpload.getFiles().getFile(0).getFileExt();
	String fileName = its.getIPTimeRand() + "." + ext;
	String path = "/Index/images/upload/" + fileName;
	mySmartUpload.getFiles().getFile(0).saveAs(path, 1);
	if (type.equals("yiji")) {
		String name = mySmartUpload.getRequest().getParameter("yiji");
		ProTypeBean ptype = new ProTypeBean();
		ptype.setPtype_name(name);
		ptype.setPtype_url(path.substring(7));
		boolean flag = DAOFactory.getIProTypeDAOInstance().create(ptype);
		if (flag) {
			out.println("<script>alert('添加成功！');</script>");
			response.setHeader("refresh", "0;url=typeAdd1.jsp");
		} else {
			out.println("<script>alert('添加失败！');</script>");
			response.setHeader("refresh", "0;url=typeAdd1.jsp");
		} 
	}
	if (type.equals("erji")) {
		int yj = Integer.parseInt(mySmartUpload.getRequest().getParameter("yi"));
		String ej = mySmartUpload.getRequest().getParameter("erji");
		ProTypeBean ptype = new ProTypeBean();
		ptype.setParent_id(yj);
		ptype.setPtype_name(ej);
		ptype.setPtype_url(path.substring(7));
		boolean flag = DAOFactory.getIProTypeDAOInstance().createType(ptype);
		if (flag) {
			out.println("<script>alert('添加成功！');</script>");
			response.setHeader("refresh", "0;url=typeAdd2.jsp");
		} else {
			out.println("<script>alert('添加失败！');</script>");
			response.setHeader("refresh", "0;url=typeAdd2.jsp");
		} 
	}
%>
</body>
</html>